/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/

package xxhci.oracle.apps.XXIERP.ubot.webui;

import java.io.Serializable;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;


/**
 * Controller for ...
 */
public class MainController extends OAControllerImpl {
    public static final String RCS_ID = "$Header$";
    public static final boolean RCS_ID_RECORDED = 
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);

        System.out.println("LoginName:" + 
                           pageContext.getUserName());
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        Serializable[] initParams = { pageContext.getUserName() };
        am.invokeMethod("initOTPer", initParams);
        OAMessageTextInputBean PersonId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("PersonId");
        String PersonId1 = (String)PersonId.getValue(pageContext);
        Serializable[] initParams1 = { PersonId1 };
        am.invokeMethod("initOTHdr1", initParams1);


    }

    /**
     * Procedure to handle form submissions for form elements in
     * a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);

        if (pageContext.getParameter("Create") != null) {
            String Vstatus = "Create";

            OAMessageTextInputBean PersonId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("PersonId");
            OAMessageTextInputBean LastName = 
                (OAMessageTextInputBean)webBean.findChildRecursive("LastName");
            OAMessageTextInputBean EmployeeNumber = 
                (OAMessageTextInputBean)webBean.findChildRecursive("EmployeeNumber");
            OAMessageTextInputBean FirstName = 
                (OAMessageTextInputBean)webBean.findChildRecursive("FirstName");
            OAMessageTextInputBean Grade = 
                (OAMessageTextInputBean)webBean.findChildRecursive("Grade");
            OAMessageTextInputBean Organization = 
                (OAMessageTextInputBean)webBean.findChildRecursive("Organization");
            String PersonId1 = (String)PersonId.getValue(pageContext);
            String LastName1 = (String)LastName.getValue(pageContext);
            String EmployeeNumber1 = 
                (String)EmployeeNumber.getValue(pageContext);
            String FirstName1 = (String)FirstName.getValue(pageContext);
            String Grade1 = (String)Grade.getValue(pageContext);
            String Organization1 = (String)Organization.getValue(pageContext);
            System.out.println("EmpSearchCO: processing create/update" + 
                               PersonId);

            /*  pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/XXIERP/LabExamples/webui/Create_PG&akRegionApplicationId=20003&menu=Y&addBreadCrumb=RS&retainAM=Y&Status="+Vstatus+"&pPersonId="+PersonId1+"&pLastName="+LastName1+"&pEmployeeNumber="+EmployeeNumber1+"&pFirstName="+FirstName1+"&pGrade="+Grade1,
              null,
              OAWebBeanConstants.KEEP_MENU_CONTEXT,
              null, null, true,
              OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
              OAWebBeanConstants.IGNORE_MESSAGES);
              */

            pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/XXIERP/ubot/webui/Create_PG_old&Status=" + 
                                      Vstatus + "&pPersonId=" + PersonId1 + 
                                      "&pLastName=" + LastName1 + 
                                      "&pEmployeeNumber=" + EmployeeNumber1 + 
                                      "&pFirstName=" + FirstName1 + 
                                      "&pGrade=" + Grade1, null, 
                                      OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                      null, null, true, 
                                      OAWebBeanConstants.ADD_BREAD_CRUMB_YES, 
                                      OAException.ERROR);


        }
    }

}
